﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Venta
{
    public partial class Insertar: Form
    {
        public MySqlConnection conexio = new MySqlConnection();
        public MySqlCommand comando;
        public int temporal;
        public string regresarvalor;
        public Insertar()
        {
            InitializeComponent();
        }

        private void btnguardar_Click(object sender, EventArgs e)
        {
            try
            {
                Conectar();
                comando = new MySqlCommand("SELECT MAX(ID_BOLETOS) FROM Boletos", conexio);
                if (Convert.ToString(comando.ExecuteScalar()) == "")
                    temporal=0;
                else temporal = int.Parse(Convert.ToString(comando.ExecuteScalar()));
                    for (int i = 1; i <= int.Parse(txtcantidad.Text); i++)
                    {
                        temporal += 1;
                        comando = new MySqlCommand("insert into Boletos values(" + (temporal).ToString() + ",50)", conexio);
                        comando.ExecuteNonQuery();
                    }
                    conexio.Close();
                    regresarvalor = temporal.ToString();
                    this.Close();
                
            }
            catch 
            {
                MessageBox.Show("No se pudieron Insertar");
            }
        }
        private void Conectar()
        {
            try
            {
                conexio.ConnectionString = "Server=instance29023.db.xeround.com;Port=18932;Database=ventaboletos;Uid=petty; Pwd=petty;";
               // conexio.ConnectionString = "Server=127.0.0.1;Database=ventaboletos;Uid=root; Pwd=petty;";
                conexio.Open();
            }
            catch
            {
                MessageBox.Show("No se realizo");
            }
        }
    }
}
